use zmath::{ Vec2, Mat4 };

pub trait Camera {
    fn mat(&self) -> Mat4;
}

pub struct Camera2D {
    position: Vec2,
    scale: f32,
    combination: Mat4,
}

impl Camera for Camera2D {
    fn mat(&self) -> Mat4 {
        self.combination
    }
}

impl Camera2D {
    pub fn new() -> Self {
        Self {
            position: Vec2(0.0, 0.0),
            scale: 1.0,
            combination: Mat4::identity(),
        }
    }

    pub fn set_position(&mut self, position: Vec2) {
        self.position = position;
        self.compute_matrix();
    }

    pub fn set_scale(&mut self, scale: f32) {
        self.scale = scale;
        self.compute_matrix();
    }

    pub fn compute_matrix(&mut self) {
        self.combination = Mat4::identity();
        self.combination.translate(-self.position.0, -self.position.1, -1.0);
        self.combination.scale(self.scale, self.scale, self.scale);
    }
}